package com.csw.android.ffmpegtest.ui.section7

import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.csw.android.ffmpegtest.R
import com.csw.android.ffmpegtest.databinding.ItemSection201WavListBinding
import java.io.File

class AacFileAdapter(val fragment: Fragment) :
    BaseQuickAdapter<File, BaseDataBindingHolder<ItemSection201WavListBinding>>(R.layout.item_section_201_wav_list) {
    override fun convert(holder: BaseDataBindingHolder<ItemSection201WavListBinding>, item: File) {
        holder.dataBinding?.wavFile = item
        holder.dataBinding?.section201ViewModel =
            ViewModelProvider(fragment).get(Section701ViewModel::class.java)
        holder.dataBinding?.section201ViewModel?.filePlayState?.observe(fragment) {
            val progress = it[item.path]
            if (progress != null) {
                holder.dataBinding?.progress?.visibility = View.VISIBLE
                holder.dataBinding?.progress?.progress = progress
            } else {
                holder.dataBinding?.progress?.visibility = View.GONE
            }
        }
    }
}